package com.sophic_tech.hkb.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class ResourceModelVO extends ResourceModel {
    // 发布用户用户名 非数据库字段
    @TableField(value = "username")
    private String publishUsername;

    public static ResourceModelVO fromResourceModel(ResourceModel resourceModel) {
        if (resourceModel == null) {
            return null;
        }
        // 将 ResourceModel 转换为 ResourceModelVO（类似复制）
        ResourceModelVO vo = new ResourceModelVO();
        vo.setId(resourceModel.getId());
        vo.setTitle(resourceModel.getTitle());
        vo.setIntroduction(resourceModel.getIntroduction());
        vo.setResourceURL(resourceModel.getResourceURL());
        vo.setUserId(resourceModel.getUserId());
        vo.setIsVipOnly(resourceModel.getIsVipOnly());
        vo.setStatus(resourceModel.getStatus());
        vo.setLocation(resourceModel.getLocation());
        vo.setCreateTime(resourceModel.getCreateTime());
        vo.setResourceTag(resourceModel.getResourceTag());
        vo.setUser(resourceModel.getUser());

        if (resourceModel.getUser() != null) {
            vo.setPublishUsername(resourceModel.getUser().getUsername());
        }
        
        return vo;
    }
}
